import numpy as np 
import numpy.random as nr
import scipy
import scipy.misc
import Image as im
import cv2.cv as cv # openCV
from libtiff import TIFF


class snake_image:
    def __init__(self):
        x = np.linspace(-1,1,500)
        X,Y = np.meshgrid(x,x)
        image = np.zeros(X.shape)
        sigmaX = 0.3
        sigmaY = 0.3
        muX = 0
        muY = 0
        sobelimg = np.zeros(X.shape)
        edgeimg = np.zeros(X.shape)
        
####### normal circle with raidus 0.5
        image = 0.5*(X**2+Y**2)<0.25
        
####### blurred circle
#        image = 2*np.exp(-(((X-muX)**2)/(2*sigmaX**2))-(((Y-muY)**2)/(2*sigmaY**2)))
       
####### Moon
#        image2 = 12*np.exp(-(((X-0.2)**2)/(2*sigmaX**2))-(((Y-muY)**2)/(2*sigmaY**2)))
#        image = image2 + image
#        image[(image>1).nonzero()] = 1 # normalize, because some values > 1
#        image = image - image2
#        image[(image<0).nonzero()] = 0
        
####### Ring
#        sigmaX2 = 0.2
#        sigmaY2 = 0.2
#        image2 = 2*np.exp(-(((X-muX)**2)/(2*sigmaX2**2))-(((Y-muY)**2)/(2*sigmaY2**2)))
#        image = image - 2*image2
        
####### add noise
#        image = image + 0.1 + nr.normal(0.0,0.05,size=X.shape)#
        
####### Putting in roof and ceiling
        image[(image<0).nonzero()] = 0
        image[(image>1).nonzero()] = 1
         
####### Making an RGB image out of the circle
        im_rgb = np.zeros([500,500,3])
        im_rgb[:,:,0] = image[:]
        im_rgb[:,:,2] = 1-image[:]
        
####### Making the image 8-bit
        self.image = (im_rgb*255).astype(np.uint8)     
        scipy.misc.imsave('cirk.png', self.image)
        
####### Sobel
#        image = cv.LoadImageM('cirk.png', cv.CV_LOAD_IMAGE_GRAYSCALE)
#        sobelimg = cv.CreateMat(image.height, image.width, cv.CV_16S )
#        cv.Sobel(image, sobelimg, 2, 2, apertureSize = 5)
#        scipy.misc.imsave('sobelimg.png', sobelimg)
        
####### Canny
        image = cv.LoadImageM('cirk.png', cv.CV_LOAD_IMAGE_GRAYSCALE)
        cannyimg = cv.CreateMat(image.height, image.width, cv.CV_8U )
        cv.Canny(image, cannyimg, 10, 60, 3)
        scipy.misc.imsave('cannyimg.png', cannyimg)


S = snake_image()
